﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Net;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Animation;
using System.Windows.Shapes;
using Microsoft.Phone.Controls;
using System.IO.IsolatedStorage;
using System.IO;
using System.Windows.Media.Imaging;
using ImageTools;
using ImageTools.Controls;
using ImageTools.IO;
using ImageTools.IO.Bmp;
using ImageTools.IO.Png;
using ImageTools.IO.Gif;
using System.Diagnostics;

namespace luGIF微电影.View
{
    public partial class ShowPicsPage : PhoneApplicationPage
    {

        public ShowPicsPage()
        {
            InitializeComponent();
           
            Decoders.AddDecoder<BmpDecoder>();
            Decoders.AddDecoder<PngDecoder>();
            Decoders.AddDecoder<GifDecoder>();
            
            
        }
        protected override void OnNavigatedTo(System.Windows.Navigation.NavigationEventArgs e)
        {
            IsolatedStorageFile isf = IsolatedStorageFile.GetUserStoreForApplication();
            String[] filenames = isf.GetFileNames();
            int count = filenames.Count();
            int i = 0;
            foreach (string fname in filenames)
            {
                IsolatedStorageFileStream isfs = new IsolatedStorageFileStream(fname, FileMode.Open, isf);

                ExtendedImage image = new ExtendedImage();

                GifDecoder gc = new GifDecoder();
                try
                {
                    gc.Decode(image, isfs);

                    AnimatedImage animatedImage = new AnimatedImage();
                    animatedImage.Source = image;

                    Grid.SetRow(animatedImage, i / 3);
                    Grid.SetColumn(animatedImage, i % 3);
                    animatedImage.Margin = new Thickness(0, 0, 10, 0);
                    ImageBoard.Children.Add(animatedImage);
                    i++;
                }
                catch (Exception ee)
                {
                    Debug.WriteLine(ee.Message);
                }
                isfs.Close();
            }

            base.OnNavigatedTo(e);
        }
        private async void readGifImage()
        {

            return ;
        }
        private void button1_Click(object sender, RoutedEventArgs e)
        {

        }
    }
}